package com.ideal.manage.esms.repository.diagnostic;

import com.ideal.manage.esms.bean.project.StadningBookInfo;
import com.ideal.manage.esms.bean.project.AccountProperty;
import com.ideal.manage.esms.bean.project.EquipmentManage;
import com.ideal.manage.esms.bean.project.ProjectManage;
import com.ideal.manage.esms.repository.framework.BaseRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created By Dai On 2018/5/18
 * Remark: 系统监控-台账信息存储表 Repository
 */
public interface StadningBookInfoRepository extends BaseRepository<StadningBookInfo, String> {

    /**
     * 查询已有未删除的数据
     *
     * @param result          台账配置列表
     * @param equipmentManage 设备id
     * @return
     */
    @Query("select s from StadningBookInfo s where s.equipment=?2 and s.isValid=1 and s.account in ?1")
    List<StadningBookInfo> findByAccountPropertyAndEquipmentManage(List<AccountProperty> result, EquipmentManage equipmentManage);

    /**
     * 查询已有未删除的数据
     *
     * @param result        台账配置列表
     * @param projectManage 项目id
     * @return
     */
    @Query("select s from StadningBookInfo s where s.project=?2 and s.isValid=1 and s.account in ?1")
    List<StadningBookInfo> findByAccountPropertyAndProjectManage(List<AccountProperty> result, ProjectManage projectManage);

    /**
     * 查询已有未删除的数据
     *
     * @param equipmentManage 设备id
     * @return
     */
    @Query("select s from StadningBookInfo s where s.equipment=?1 and s.isValid=1")
    List<StadningBookInfo> findByEquipmentManage(EquipmentManage equipmentManage);

    /**
     * 查询已有未删除的数据
     *
     * @param projectManage 项目id
     * @return
     */
    @Query("select s from StadningBookInfo s where s.project=?1 and s.isValid=1")
    List<StadningBookInfo> findByProjectManage(ProjectManage projectManage);

    /**
     * 找到所有项目信息的台账
     *
     * @return
     */
    @Query("select s from StadningBookInfo s where s.isValid=1 and s.project.isValid=1 and s.account.parameterType=1 and s.project is not null order by s.project")
    List<StadningBookInfo> findStadningBookInfo();

    @Query("select s from StadningBookInfo s where s.account.id=?1 and s.isValid=1 and s.project.id=?2")
    StadningBookInfo findByAccountId(String id, String projectId);
}
